﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Micronet.OpenWeb.Com.BLL;
using Micronet.OpenWeb.Com.Controls;
using Micronet.OpenWeb.Common;
using Micronet.OpenWeb.Entity;
using Micronet.OpenWeb.Utils;

namespace Micronet.OpenWeb.OpenWeb.Admin.Views.Shared.OpenPersonality
{
    public partial class HomeProfileContactInfosEdit1 : System.Web.UI.UserControl
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (OwConstants.QueryString.ID.OwQsIsExist())
            {
                HomeProfileContactInfosOwDv.DefaultMode = DetailsViewMode.Edit;
            }
            else
            {
                HomeProfileContactInfosOwDv.DefaultMode = DetailsViewMode.Insert;

            }
            HomeProfileContactInfosOds.Inserted += new ObjectDataSourceStatusEventHandler(HomeProfileContactInfosOds_Inserted);
            HomeProfileContactInfosOds.Updated += new ObjectDataSourceStatusEventHandler(HomeProfileContactInfosOds_Updated);
            HomeProfileContactInfosOds.Deleted += new ObjectDataSourceStatusEventHandler(HomeProfileContactInfosOds_Deleted);
        }

        void HomeProfileContactInfosOds_Deleted(object sender, ObjectDataSourceStatusEventArgs e)
        {
            Response.Redirect("HomeProfileContactInfosAdmin.aspx");
        }

        void HomeProfileContactInfosOds_Updated(object sender, ObjectDataSourceStatusEventArgs e)
        {
            Response.Redirect("HomeProfileContactInfosAdmin.aspx");

        }

        void HomeProfileContactInfosOds_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
        {
            Response.Redirect("HomeProfileContactInfosAdmin.aspx");

        }
        void UniqueProcess(object sender, ObjectDataSourceStatusEventArgs e)
        {
            var IsDefaultCb = (OwCheckBox)HomeProfileContactInfosOwDv.FindControl("IsDefaultCb");
            if (IsDefaultCb.Checked.ToString().OwToBoolean() == true)
            {
                var ods = OwOpenHomeProfileContactInfosBLL.OwGetByDynamic(isDefault: true);
                foreach (var entity in ods)
                {
                    var en = OwOpenHomeProfileContactInfosBLL.OwGetEntity(e.ReturnValue.OwToInt64TryParse());
                    if (en.OpenHomeProfileContactInfoID != entity.OpenHomeProfileContactInfoID)
                    {
                       
                        entity.IsDefault = false;
                        OwOpenHomeProfileContactInfosBLL.OwSave(entity);
                        
                    }
                }
            }
        }


    }
}